home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Commands / Jump Menu.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  5.2 KB  |  186 lines

  1.  
  2. // Copyright 1999 Macromedia, Inc. All rights reserved.
  3.  
  4. //////
  5.  
  6. //*************************GLOBAL VARS********************
  7.  
  8. var helpDoc = MM.HELP_objJumpMenu;
  9.  
  10. //form objects
  11. var GlistOptions;
  12. var GtfLabel;
  13. var GtfURL;
  14. var GtfName;
  15. var GselTarget;
  16. var GcbRestore
  17. var GcbGo;
  18.  
  19.  
  20. var GarrMenuOptions;  //global array storing menu option text and URLs
  21.                      
  22.  
  23. //function: initGlobals
  24. //description: initialize global variables
  25.  
  26. function initGlobals(){
  27.  
  28.    var theForm = document.forms[0];
  29.    GlistOptions = theForm.MenuOptions;
  30.    GtfURL = theForm.fileURL;
  31.    GtfLabel = theForm.Label;
  32.    GtfName = theForm.Name;
  33.    GselTarget = theForm.Target;
  34.    GcbRestore = theForm.Restore;
  35.    GcbGo = theForm.Go; 
  36.    
  37.    GarrMenuOptions = new Array();
  38.    GarrMenuOptions[0] = new Array();
  39.    GarrMenuOptions[0][0] = getUniqueLabel();
  40.    GarrMenuOptions[0][1] = "";
  41. }
  42.  
  43. //***************************API FUNCTIONS*****************************
  44.  
  45. function commandButtons(){
  46.    return new Array(BTN_OK,        "okClicked()",
  47.                     BTN_Cancel,    "cancelClicked()",          
  48.                     BTN_Help,      "displayHelp()"  );
  49.  
  50. }
  51.  
  52. //***************************LOCAL FUNCTIONS*****************************
  53.  
  54. //function: okClicked
  55. //description: creates the jump menu that is inserted into the document
  56.  
  57. function okClicked(){ 
  58.    
  59.    var target = escQuotes(GselTarget.options[GselTarget.selectedIndex].value);
  60.    var bRestore = (GcbRestore.checked)?1:0;
  61.    var bInsideForm = IPIsInsideOfForm();
  62.    var nOptions = GarrMenuOptions.length,i,attrPos;
  63.    var optionStr="",formObjArr,uniqueFormName;
  64.    
  65.    //create opening of select tag
  66.    var menuStr = '<SELECT name="' + GtfName.value + '" ' +
  67.               'onChange="MM_jumpMenu(\'' + target + '\',this,' + bRestore + ')">\n';
  68.    
  69.    //create inner options string, i.e.:<option value="foo">label</option> 
  70.    for (i=0;i<nOptions;i++){
  71.       if (GarrMenuOptions[i][0] || GarrMenuOptions[i][1]){
  72.          optionStr = (GarrMenuOptions[i][1])?'<option value="' + GarrMenuOptions[i][1] + '">':
  73.                                              '<option>';                   
  74.          optionStr += GarrMenuOptions[i][0] + '</option>\n';
  75.          menuStr += optionStr;
  76.       }
  77.    }
  78.    menuStr += '</select>';       
  79.    
  80.    //if the "Insert a Go Button" is checked, then add a Go button
  81.    if (GcbGo.checked){
  82.       menuStr += createGoBtnStr(target,bRestore);
  83.    }
  84.    
  85.    //add a form to the document if one is not there already     
  86.    if ( !bInsideForm  ){ //if there isn't a form, add one
  87.       uniqueFormName = createUniqueName("FORM","form");
  88.       menuStr = '<form name="' + uniqueFormName + '">' + menuStr + '\n</form>';     
  89.    }  
  90.    MM.commandReturnValue = menuStr;
  91.    window.close();
  92. }    
  93.  
  94.  
  95.  
  96. function cancelClicked() {
  97.   MM.commandReturnValue = "";
  98.   window.close();
  99. }
  100.  
  101.  
  102. //function: createGoBtnStr
  103. //description: creates the text string for the go button
  104.  
  105. function createGoBtnStr(target,bRestore){
  106.  
  107.    var btnStr="";
  108.    
  109.    //get the select menu name
  110.    objName = GtfName.value;
  111.    
  112.    //create unique button name
  113.    var btnName = createUniqueName("INPUT","Button");
  114.  
  115.    //piece together button string 
  116.    btnStr += '<INPUT type="button" name="' + btnName + '" value="' + BTN_Go + '" ' +
  117.               'onClick="MM_jumpMenuGo(\'' + objName + '\',\'' + target + '\',' + bRestore + ')">';
  118.                   
  119.    return ( btnStr );
  120.  
  121. }
  122.  
  123. //function: initializeUI
  124. //description: initializes the UI, attached to body onload
  125. function initializeUI(){
  126.    initGlobals();
  127.    
  128.    //initial state of dialog is that "Option Label" appears in Lable field,
  129.    //"Option URL" appears in URL field, and the lable field selected
  130.    populateMenuOptions(0);
  131.    GlistOptions.selectedIndex = 0; 
  132.    GtfLabel.value = GarrMenuOptions[0][0];
  133.    GtfURL.value = GarrMenuOptions[0][1];
  134.    GtfLabel.focus();
  135.    GtfLabel.select();
  136.    
  137.    //populate frame target menu
  138.    populateFrameTargetMenu(GselTarget);
  139.    
  140.    //create a unique name for this menu
  141.    GtfName.value = createUniqueName("SELECT","menu");
  142. }
  143.  
  144. //function: popuplateFrameTargetMenu
  145. //description: populates the frame target menu with either:
  146. //"Main Window" - if there are no frames
  147. //"Main Window" plus named frames, if there are frames
  148.  
  149. function populateFrameTargetMenu(selectObj){
  150.    var counter = 0;
  151.    var frameList;
  152.    
  153.    selectObj.options[counter] = new Option(TYPE_MainWindow);
  154.    selectObj.options[counter++].value = 'parent';
  155.    
  156.    frameList=getObjectRefs("NS 4.0","parent","frame"); //get list of frames
  157.    if (frameList && frameList.length>0) { //if frames
  158.    //if the frame has a name, add name to target picklist
  159.       for (i=0; i<frameList.length; i++) {
  160.          if (frameList[i].indexOf('unnamed')==-1){ //if the frame has a name
  161.             frameName=extrapolateFrameName(frameList[i]);
  162.             selectObj.options[counter] = new Option(TYPE_Frame + ' "' + frameName + '"');
  163.             selectObj.options[counter++].value = frameList[i];
  164.          }
  165.       }
  166.     }
  167.    
  168.     //select the "Main Window" item
  169.     selectObj.selectedIndex = 0;
  170. }
  171.  
  172. //function: extrapolateFrameName
  173. //description: given a frame reference, extrapolates the frame's name
  174.  
  175. function extrapolateFrameName(frameRef){
  176.    return frameRef.substring(frameRef.indexOf("['")+2,frameRef.indexOf("']"));
  177. }
  178.  
  179.  
  180.  
  181. //****************************GLOBAL FUNCTIONS***************************
  182.  
  183. //createUniqueName
  184. //IPisInsideOfForm
  185. //isLayer
  186.